package org.smile.design.prototype.deepCopy;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
class Brain implements Cloneable {
    private Integer neuron;
    private String type;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

@Data
@AllArgsConstructor
class Bear implements Cloneable {

    private String name;
    private Integer age;
    private String[] hobbies;
    private Brain brain;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Bear b = (Bear) super.clone();
        b.brain = (Brain) this.brain.clone();
        return b;
    }
}

public class PrototypeBearDeepCopy {
    public static void main(String[] args) throws CloneNotSupportedException {
        String[] hobbies = {"basketball"};
        Brain brain1 = new Brain(100, "hype");
        Bear a = new Bear("Gerut", 10, hobbies, brain1);

        Bear b = (Bear) a.clone();
        System.out.println(a.getBrain().getNeuron().equals(b.getBrain().getNeuron()));
        b.getBrain().setNeuron(300);
        System.out.println(a.getBrain().getNeuron().equals(b.getBrain().getNeuron()));
    }
}